<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/11/7
  Time: 16:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>


<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>收益记录</title>
</head>
<body ontouchstart="">
<div class="detailTop pf w100 of">
    <div class="w100 of tc c3 f18">
       <span class="pa" style="left: 5px;" onclick="javascript:history.back();"><img src="mb/images/top_back.png" style="margin-top: 4px;height: 40px;width: 40px;"/></span>
        收益记录
    </div>
</div>

<div id="container" class="container jz" style="padding-top: 41px;">

    <div id="resText"></div><!--resText-->
    <div id="loading" class="w100">
        <img src="mb/images/loading.gif" alt="正在加载" class="db jz hauto" style="width: 15px;">
        <div class="w100 tc f10 c9">正在加载</div>
    </div>
</div><!--container-->

<script>

    var curpage = 1;
    var total = 1;

    /**
     * 加载新数据
     */
    function getData() {
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1780, curpage: curpage}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg()
            },
            success: function (data) {
                if (data.state == 1) {
                    // 刷新页面
                    total = data.total;
                    refreshPage(data.list);
                } else {
                    // 其他错误弹出提示
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    }

    function getItemHtml(data) {
        var rmbStyle = 'class="fr cred"';
        if (parseFloat(data.rmb) < 0) {
            rmbStyle = 'class="fr cgreen"';
        }

        var html = ''
                + '<section class="rankingBlock w100 clearfix of" style="width: 92%;">'
                    + '<div class="fl">'
                        + '<p class="f16 c3 lh15">' + data.typename + '</p>'
                        + '<p class="f12 c9 lh2">' + dataToString(data.time, "yyyy-MM-dd HH:mm:ss")  + '</p>'
                    + '</div>'
                    + '<div ' + rmbStyle + ' style="margin-top: 7px;">'
                       + '<span class="f14">&yen;</span><i class="mgl10 f20">' + data.rmb + '</i>'
                    + '</div>'
                + '</section>'
                + '<div class="baitiaoLineMoney" style="width: 92%">'
                    + '<p class="w100" style="background: #E7E7E7"></p>'
                    + '<p class="w100" style="background: #FFFFFF"></p>'
                + '</div>'
                + '';

        return html;
    }

    /**
     * 刷新列表页面
     * @param data
     */
    function refreshPage(data) {
        var html = '<div id="resText"></div>'
                + '<div id="loading" class="w100">'
                + '<img src="mb/images/loading.gif" alt="正在加载" class="db jz hauto" style="width: 15px;">'
                + '<div class="w100 tc f10 c9">正在加载</div>'
                + '</div>';
        $("#container").html(html);

        if (data == null) {
            showToast("暂无收益记录！");
            return;
        }

        html = '';

        for (var i = 0; i < data.length; i++) {
            html += getItemHtml(data[i])
        }

        $("#resText").before($(html));
    }

    $(function () {
        $(window).bind('scroll', function () {
            show()
        });
    });

    function show() {
        if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
            loadNext();
        }
    }

    /**
     * 加载下一页数据
     */
    function loadNext() {
        if (curpage < total) {
            curpage++;

            $.ajax({
                url: "PlugServlet",
                data: JSON.stringify({m: 1780, curpage: curpage}),
                type: 'post',
                dataType: 'json',
                contentType: "application/json;charset=utf-8",
                beforeSend: function () {
                    $("#loading").show();
                },
                success: function (data) {
                    if (data.state == 1) {
                        // 刷新页面
                        total = data.total;
                        // 加载更多
                        if (data.list != null) {
                            var html = '';
                            for (var i = 0; i < data.length; i++) {
                                html += getItemHtml(data[i])
                            }

                            $("#resText").before($(html));
                        }
                    } else {
                        // 其他错误弹出提示
                        showToast(data.info);
                    }
                },
                error: function (data) {
                    showToast(data.info);
                },
                complete: function () {
                    $("#loading").hide();
                }
            });
        } else {
            $("#loading").hide();
        }
    }

    curpage = 1;
    getData();

</script>

</body>
</html>
